﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xinkui.WebModel.BasicClass;
using CommonFramework.Utility;
using Xinkui.DataAccess.User;
using Xinkui.Entity.User;
using Xinkui.WebModel;
using Xinkui.WebModel.Helper;
using CommonFramework.Storage.Cookie;
using Xinkui.Common;
public partial class login : PageBase {

    protected string UserName { get; set; }
    /// <summary>
    /// 页面加载操作
    /// </summary>
    protected override void BindDataSource() {
        base.BindDataSource();
        if (!this.IsPostBack) {
            try {
                UserName = CookieManager.Get(SystemConst.CookieConst.LoginUserName);
            }
            catch { }

        }
    }

    /// <summary>
    /// 表单提交数据处理
    /// </summary>
    protected override void HandlePostActions() {
        base.HandlePostActions();

        string userName = WebHelper.GetFormValue<string>("userName", string.Empty);
        string pwd = WebHelper.GetFormValue<string>("password", string.Empty);

        int chkRember = WebHelper.GetFormValue<int>(" chkRemember", 0);

        LoginUserEntity loginUser = UserManager.Login(userName, pwd);
        if (chkRember == 1) {
            CookieManager.Set(SystemConst.CookieConst.LoginUserName, userName);
        }
        if (loginUser != null && loginUser.CompanyID > 0) {
            string refUrl = WebHelper.GetQueryStringValue<string>("ref");
            if (string.IsNullOrEmpty(refUrl)) {
                Response.Redirect(URLHelper.LinkToUserCenter());
            }
            else {
                Response.Redirect(refUrl);
            }
        }
        else {
            UIHelper.ShowErrorTips("Username not exists or Password not Valid");
        }
    }


}